import com.beans.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


//使用注解更加简洁方便的存储 bean
public class App {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-config.xml");

        //类注解
        UserController userController = applicationContext.getBean("userController",UserController.class);
        userController.Sayhi("UserController");

        UserService userService = applicationContext.getBean("userService",UserService.class);
        userService.Sayhi("UserService");

        UserRepository userRepository = applicationContext.getBean("userRepository",UserRepository.class);
        userRepository.Sayhi("UserRepository");

        UserConfiguration userConfiguration = applicationContext.getBean("userConfiguration",UserConfiguration.class);
        userConfiguration.Sayhi("UserConfiguration");

        /*通常我们 bean 使⽤的都是标准的⼤驼峰命名，⽽读取的时候⾸字⺟⼩写就可以获取到 bean 了。
        然⽽，当我们⾸字⺟和第⼆个字⺟都是⼤写时，就不能正常读取到 bean 了,此时直接写原类名就行*/
        APPUser appUser = applicationContext.getBean("APPUser",APPUser.class);
        appUser.Sayhi("GG");

        //方法注解
        //User user = (User) applicationContext.getBean("user1");
        User user = applicationContext.getBean("user1",User.class);
        System.out.println(user.toString());
    }
}
